﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GraphsLab5
{
    class ConnectionList
    {

        List<List<int> > a;

        public ConnectionList(List<List<int> > lines)
        {
            a = lines;
        }

        public int Length
        {
            get
            {
                return a.Count;
            }
        }

        public List<int> this[int i]
        {
            get
            {
                if (a[i] != null) return a[i];
                return new List<int>();
            }
        }

        public double diametr(List<Point> points, out List<Point> result)
        {
            result = new List<Point>();
            double max = 0;
            for (int i = 0; i < a.Count; i++)
            {
                for (int j = 0; j < a[i].Count; j++)
                {
                    double s = Math.Sqrt((points[i].X - points[a[i][j] - 1].X) * (points[i].X - points[a[i][j] - 1].X)
                        + (points[i].Y - points[a[i][j] - 1].Y) * (points[i].Y - points[a[i][j] - 1].Y));
                    if (s > max)
                    {
                        max = s;
                        result.Clear();
                        result.Add(new Point(i, a[i][j] - 1));
                    }
                    else if (s == max) result.Add(new Point(i, a[i][j] - 1));
                }
            }
            return max;
        }

        public override string ToString()
        {
            string s = "";
            for (int i = 0; i < a.Count; i++)
            {
                if (a[i].Count == 0) s += "Point " + (i + 1).ToString() + " isn't connected with any other point;";
                else {
                    s += "Point " + (i + 1).ToString() + " is connected with points #:";
                    for (int j = 0; j < a[i].Count; j++)
                    {
                        s += " " + a[i][j].ToString() + ",";
                    }
                    s = s.Remove(s.Length - 1);
                    s += ";";
                }
                s += "\n";
            }
            s = s.Remove(s.Length - 2);
            s += ".";
            return s;
        }

        public string ToString(bool lines)
        {
            if (!lines) return ToString();
            string s = "";
            for (int i = 0; i < a.Count; i++)
            {                                 
                    for (int j = 0; j < a[i].Count; j++)
                    {
                        s += (i + 1).ToString() + " -------> " + a[i][j].ToString() + ";\n";
                    }
            }
            s = s.Remove(s.Length - 2);
            s += ".";
            return s;
        } 

    }
}
